package com.ittx.dzt.tiktok.service;

import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.sys.response.Result;
import com.ittx.dzt.tiktok.constant.TiktokApiConstant;
import com.ittx.dzt.tiktok.handler.AbstractBaseTiktokApiHandler;
import lombok.extern.slf4j.Slf4j;
import open.constant.PlatformApiConstant;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 获取卖家已授权店铺信息
 * <p>
 * cy.tiktok.store.info.get
 * /authorization/202309/shops （获取卖家已授权店铺信息）  https://partner.tiktokshop.com/docv2/page/6507ead7b99d5302be949ba9?external_id=6507ead7b99d5302be949ba9
 * </p>
 *
 * @author gywang
 * @since 2024-07-24
 */
@Slf4j
@Service
public class TiktokStoreInfoGetService extends AbstractBaseTiktokApiHandler<String> {
    @Override
    public String getTiktokMethod() {
        return TiktokApiConstant.STORE_INFO_GET;
    }

    @Override
    public String getLocalApiMethod() {
        return PlatformApiConstant.InboundInterface.TIKTOK_STORE_INFO_GET;
    }

    @Override
    public Result doProcess(PlatformApiParamDTO platformApiParamDTO, String deliveryOptionId) {
        Map<String, Object> params = new HashMap<>();
        Result result = this.executeTiktokApi(getDefaultUrl(platformApiParamDTO.getStoreConfig()), platformApiParamDTO.getStoreConfig(), params, null, platformApiParamDTO.getRequestId(), TiktokApiConstant.ApiHttpMethod.GET);
        if (!result.isSuccess()) {
            return result;
        }
        Map<String, Object> resultMap = (Map<String, Object>) result.getData();
        List<Map<String, Object>> list = (List<Map<String, Object>>) ((Map) resultMap.get("data")).get("shops");
        return this.sendRequestToPlatform(platformApiParamDTO, resultMap, true);
    }
}
